package com.investment.advisor.entity;

import com.fasterxml.jackson.annotation.JsonBackReference;
import com.fasterxml.jackson.annotation.JsonManagedReference;
import lombok.Getter;
import lombok.Setter;
import lombok.NoArgsConstructor;
import lombok.ToString;
import org.hibernate.annotations.CreationTimestamp;
import org.hibernate.annotations.UpdateTimestamp;

import javax.persistence.*;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.Set;

@Entity
@Table(name = "portfolios")
@Getter
@Setter
@NoArgsConstructor
@ToString(exclude = {"strategy", "portfolioFunds", "trades"})
public class Portfolio {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    @Column(nullable = false, length = 100)
    private String name;

    @JsonBackReference
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "strategy_id")
    private Strategy strategy;  // 所采用的策略

    @Column(length = 1000)
    private String description;  // 组合描述

    @Column(precision = 10, scale = 4)
    private BigDecimal performance;  // 收益表现

    @Column(precision = 10, scale = 4)
    private BigDecimal annualReturn;  // 年化收益率

    @Column(precision = 10, scale = 4)
    private BigDecimal maxDrawdown;  // 最大回撤

    @Column(precision = 10, scale = 4)
    private BigDecimal volatility;  // 波动率

    @Column(precision = 10, scale = 4)
    private BigDecimal sharpeRatio;  // 夏普比率

    @Column(length = 100)
    private String creator;  // 创建者

    @JsonManagedReference
    @OneToMany(mappedBy = "portfolio", cascade = CascadeType.ALL)
    private Set<PortfolioFund> portfolioFunds;  // 组合中的基金及权重

    @JsonManagedReference
    @OneToMany(mappedBy = "portfolio", cascade = CascadeType.ALL)
    private Set<Trade> trades;  // 交易记录

    @CreationTimestamp
    private LocalDateTime createTime;

    @UpdateTimestamp
    private LocalDateTime updateTime;
} 